#include "complex.h"

ostream& operator<< (ostream& out, Complex com)
{
    if (com.imagine () == 0)
        out << com.real ();
    else if (com.imagine () < 0)
        out << com.real () << " - " << fabs(com.imagine ()) << "i";
    else
        out << com.real () << " + " << com.imagine () << "i";

    return out;
}

Complex operator+ (double num, Complex com)
{
    com.real () += num;
    return com;
}

Complex operator- (double num, Complex com)
{
    com.real () = num - com.real ();
    com.imagine () = -com.imagine ();
    return com;
}

Complex::Complex (double re, double im): realPart (re), imagePart (im)
{
    ;
}

Complex& Complex::operator+ (Complex second)
{
    this->real () += second.real ();
    this->imagine () += second.imagine ();
    return *this;
}
    
Complex& Complex::operator- (Complex second)
{
    this->real () -= second.real ();
    this->imagine () -= second.imagine ();
    return *this;
}

Complex& Complex::operator+ (double num)
{
    this->real () += num;
    return *this;
}

Complex& Complex::operator- (double num)
{
    this->real () -= num;
    return *this;
}

double& Complex::real ()
{
    return realPart;
}

double& Complex::imagine ()
{
    return imagePart;
}

